//
//  MOAddressBookSearchViewCell.m
//  MobileOffice
//
//  Created by 冰冰 on 2019/6/10.
//  Copyright © 2019 com.idolmedia. All rights reserved.
//

#import "MOAddressBookSearchViewCell.h"

#define ICONLABELWIDTH kWConversions(39)
#define LABELWIDTH    SCREEN_WIDTH - ICONLABELWIDTH - kWConversions(14) * 3

@interface MOAddressBookSearchViewCell ()

//头像
@property(nonatomic,strong)UILabel *iconLabel;
//名字
@property(nonatomic,strong)UILabel *nameLabel;

@property(nonatomic,strong)UILabel *nameDecLabel;
//部门
@property(nonatomic,strong)UILabel *sectionLabel;
//分割线
@property(nonatomic,strong)UIView *lineView;

@end

@implementation MOAddressBookSearchViewCell

+(instancetype)cellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath
{
    //NSString *ID = [NSString stringWithFormat:@"Cell%ld%ld",(long)[indexPath section],(long)[indexPath row]];
    NSString *ID = @"MOAddressBookSearchViewCell";
    MOAddressBookSearchViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil){
        cell = [[MOAddressBookSearchViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell creatView];
    }
    return cell;
}


-(void)creatView
{
    [self addSubview:self.iconLabel];
    [self addSubview:self.nameLabel];
    [self addSubview:self.nameDecLabel];
    [self addSubview:self.sectionLabel];
    [self addSubview:self.lineView];
}

-(void)setModel:(MOAddressBookPeopleModel *)model
{
    if (model.nameStr.length==2||model.nameStr.length==1){
        self.iconLabel.text = model.nameStr;
    }else if (model.nameStr.length>=3){
        self.iconLabel.text = [model.nameStr substringWithRange:NSMakeRange(1, 2)];
    }
    
    self.nameLabel.attributedText = [NSString contentString:model.nameStr subString:model.searchContent subColor:KBlueColor_2C94FF subFont:FONT_SIZE(16)];
    
    self.nameDecLabel.attributedText = [NSString contentString:[NSString stringWithFormat:@"姓名：%@",model.nameStr] subString:model.searchContent subColor:KBlueColor_2C94FF subFont:FONT_SIZE(16)];
    self.sectionLabel.text = model.post;
    
}



#pragma mark -- 懒加载
-(UILabel *)iconLabel
{
    if (!_iconLabel) {
        _iconLabel = [[UILabel alloc]initWithFrame:CGRectMake(kWConversions(14), kHConversions(12), ICONLABELWIDTH, ICONLABELWIDTH)];
        _iconLabel.textColor = KWhiteColor;
        _iconLabel.font = [UIFont boldSystemFontOfSize:14];
        _iconLabel.textAlignment = NSTextAlignmentCenter;
        _iconLabel.layer.masksToBounds = YES;
        _iconLabel.layer.cornerRadius = ICONLABELWIDTH/2;
        _iconLabel.backgroundColor = KBlueColor_4879E8;
    }
    return _iconLabel;
}

-(UILabel *)nameLabel
{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(_iconLabel.right + kWConversions(14), _iconLabel.y + kHConversions(3), LABELWIDTH, 17)];
        _nameLabel.textColor = KBlackColor_2A2A2A;
        _nameLabel.font = FONT_SIZE(16);
    }
    return _nameLabel;
}

-(UILabel *)nameDecLabel
{
    if (!_nameDecLabel) {
        _nameDecLabel = [[UILabel alloc]initWithFrame:CGRectMake(_iconLabel.right + kWConversions(14), _nameLabel.bottom + kHConversions(5), LABELWIDTH, 13)];
        _nameDecLabel.textColor = KGrayColor_616263;
        _nameDecLabel.font = FONT_SIZE(12);
    }
    return _nameDecLabel;
}

-(UILabel *)sectionLabel
{
    if (!_sectionLabel) {
        _sectionLabel = [[UILabel alloc]initWithFrame:CGRectMake(_iconLabel.right + kWConversions(14), _nameDecLabel.bottom + kHConversions(5), LABELWIDTH, 13)];
        _sectionLabel.textColor = KGrayColor_919395;
        _sectionLabel.font = FONT_SIZE(12);
    }
    return _sectionLabel;
}

-(UIView *)lineView
{
    if (!_lineView) {
        _lineView = [[UIView alloc]initWithFrame:CGRectMake(_sectionLabel.x, _sectionLabel.bottom + kHConversions(15)-1, SCREEN_WIDTH - _sectionLabel.x, 1)];
        _lineView.backgroundColor = KGrayColor_ededed;
    }
    return _lineView;
}


@end
